package com.kylin.system.common.utils;

import com.kylin.common.poi.excel.handler.ExcelDictService;
import com.kylin.system.entity.SysDictData;
import com.kylin.system.service.SysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Excel数据字典实现类
 * @author wuhao
 * @version 1.0 - 2022/1/14
 */
@Component
public class ExcelDictServiceImpl implements ExcelDictService {

    @Autowired
    private SysDictTypeService dictTypeService;

    @Override
    public Map<String, Object> toNameMap(String dict) {
        List<SysDictData> dictDataList = dictTypeService.selectDictDataByType(dict);
        Map<String, Object> collect = dictDataList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        return collect;
    }

    @Override
    public Map<String, Object> toValueMap(String dict) {
        List<SysDictData> dictDataList = dictTypeService.selectDictDataByType(dict);
        Map<String, Object> collect = dictDataList.stream().collect(Collectors.toMap(SysDictData::getDictLabel, SysDictData::getDictValue));
        return collect;
    }
}
